package com.example.swaggerproject.controller;

import com.example.swaggerproject.entity.Book;
import com.example.swaggerproject.entity.Result;
import com.example.swaggerproject.mapper.BookMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;

@RequiredArgsConstructor
@RestController
@RequestMapping("/book")
public class BookController {

    private final BookMapper bookMapper;

    @GetMapping("/{id}")
    public Result<Book> findById(@PathVariable Long id) {
        Book book = bookMapper.findById(id);
        return Result.success(book);
    }

    @GetMapping("/")
    public Result<Collection<Book>> findAll() {
        Collection<Book> all = bookMapper.findAll();
        return Result.success(all);
    }

    @PutMapping("/{id}")
    @ResponseStatus(HttpStatus.OK)
    public Result<Book> updateBook(@PathVariable("id") final String id, @RequestBody final Book book) {
        return Result.success(book);
    }

}
